#!/usr/bin/env python
#coding:utf-8
"""
  Author:  xulie --<>
  Purpose: 
  Created: 06/29/16
"""
from peewee import Cast
from pymysql import NUMBER

FUNC_DIC = {
    'date': lambda x, y: x == (y if len(y)==10 else int(y)/1000),
    'date_gt': lambda x, y: x > (y if len(y)==10 else int(y)/1000),
    'date_lt': lambda x, y: x < (y if len(y)==10 else int(y)/1000),
    'date_gte': lambda x, y: x >= (y if len(y)==10 else int(y)/1000),
    'date_lte': lambda x, y: x <= (y if len(y)==10 else int(y)/1000),
}

def makeQueryFields(kwargs, Table):
    def _get_field(slug):
        return getattr(Table, slug)

    filters = []
    for k, v in kwargs.items():
        if '__' in k:
            f_name, func_name = k.split('__')
            field = _get_field(f_name)
            if v:
                filters.append(FUNC_DIC[func_name](field, v[0]))
        else:
            if hasattr(Table,k):
                field = _get_field(k)
                filters.append(field == v)
    return filters

def jsonPropt(astr):#给json内的键加上双引号
    return astr.replace(' ','').replace('\n','').replace('\r','')\
               .replace("'",'"')



COM_SLEEP = 0x00
COM_QUIT = 0x01
COM_INIT_DB = 0x02
COM_QUERY = 0x03
COM_FIELD_LIST = 0x04
COM_CREATE_DB = 0x05
COM_DROP_DB = 0x06
COM_REFRESH = 0x07
COM_SHUTDOWN = 0x08
COM_STATISTICS = 0x09
COM_PROCESS_INFO = 0x0a
COM_CONNECT = 0x0b
COM_PROCESS_KILL = 0x0c
COM_DEBUG = 0x0d
COM_PING = 0x0e
COM_TIME = 0x0f
COM_DELAYED_INSERT = 0x10
COM_CHANGE_USER = 0x11
COM_BINLOG_DUMP = 0x12
COM_TABLE_DUMP = 0x13
COM_CONNECT_OUT = 0x14
COM_REGISTER_SLAVE = 0x15
COM_STMT_PREPARE = 0x16
COM_STMT_EXECUTE = 0x17
COM_STMT_SEND_LONG_DATA = 0x18
COM_STMT_CLOSE = 0x19
COM_STMT_RESET = 0x1a
COM_SET_OPTION = 0x1b
COM_STMT_FETCH = 0x1c
COM_DAEMON = 0x1d
COM_BINLOG_DUMP_GTID = 0x1e
COM_END = 0x2f
print(COM_SET_OPTION,COM_CONNECT_OUT,COM_DELAYED_INSERT,COM_END)